<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>10-计算属性完整写法</title>
    <style>
        input {
            width: 30px;
        }
    </style>
</head>
<body>
    <div id="app">
        姓：<input type="text" v-model="firstName"> +
        名：<input type="text" v-model="lastName"> =
        <span>{{fullName}}</span><br><br> 
        <button @click="changeName">改名卡</button>
      </div>
      <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
      <script>
        const app = new Vue({
          el: '#app',
          data: {
            firstName: '丁',
            lastName: '晓豆'
          },
          computed: {
            // 完整写法 -> 获取（get）+ 设置（set)
            fullName: {
                // (1) 当 fullName 计算属性，被获取求值时，执行 get(有缓存，优先读缓存)
                //     会将返回值作为 求值的结果
                get () {
                    return this.firstName + this.lastName
                },
                set (value) {
                    // console.log(value.slice(0,1))
                    // console.log(value.slice(1))
                    this.firstName = value.slice(0,1)
                    this.lastName = value.slice(1)
                }
                
            }
          },
          methods: {
            changeName() {
                this.fullName = this.firstName + this.lastName
            }
          }
        })

      </script>
</body>
</html>